layout.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { redirect } from "next/navigation";
  2. import { headers } from "next/headers";
  3. import { getI18n } from "locales/server";
  4. import { paths } from "@/shared/constants/paths";
  5. import { auth } from "@/features/auth/lib/better-auth";
  6. import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
  7. import type { LayoutParams } from "@/shared/types/next";
  8. export default async function AuthLayout(props: LayoutParams<{}>) {
  9. const t = await getI18n();
  10. const headerStore = await headers();
  11. const searchParams = Object.fromEntries(new URLSearchParams(headerStore.get("searchParams") || ""));
  12. const translatedError = t(`next_auth_errors.${searchParams.error}` as keyof typeof t);
  13. const user = await auth.api.getSession({ headers: headerStore });
  14. if (user) {
  15. redirect(`/${paths.root}`);
  16. }
  17. return (
  18. <>
  19. <div className="h-full flex">
  20. {searchParams.error && (
  21. <Alert className="mb-4" variant="error">
  22. <AlertTitle>{translatedError}</AlertTitle>
  23. <AlertDescription>{t("signin_error_subtitle")}</AlertDescription>
  24. </Alert>
  25. )}
  26. <div className="flex flex-1 items-center justify-center">
  27. <div className="w-full max-w-md">{props.children}</div>
  28. </div>
  29. </div>
  30. </>
  31. );
  32. }